/**
 * 
 */
package com.calf.module.loan.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.calf.cn.controller.BaseController;
import com.calf.cn.entity.DataTables;
import com.calf.cn.service.BaseManager;
import com.calf.cn.utils.SearchUtil;
import com.calf.module.loan.entity.UserDetails;

/**
 * @ClassName CustomerController
 * @Description Description
 * @author wuzg
 * @Date 2017年3月13日 上午8:40:59
 * @version 1.0.0
 */
@Controller
@RequestMapping("/userdetails")
public class UserdetailsController implements BaseController<UserDetails> {

	@Autowired
	private BaseManager baseManager;
	
	/* (非 Javadoc)
	 * Description:
	 * @see com.calf.cn.controller.BaseController#home()
	 */
	@Override
	public String home() {
		return "calfloan/userdetails/userdetailslist";
	}

	/* (非 Javadoc)
	 * Description:
	 * @see com.calf.cn.controller.BaseController#initTable(javax.servlet.http.HttpServletRequest)
	 */
	@Override
	public DataTables<UserDetails> initTable(HttpServletRequest request) {
		@SuppressWarnings("unchecked")
		Map<String,Object> parameters = SearchUtil.convertorEntitysToMap(request.getParameterMap());
		String sEcho = (String)parameters.get("sEcho");
		List<UserDetails> userDetails = baseManager.query(UserDetails.class,parameters);
		int total = baseManager.get("UserDetails.queryCount", parameters);
		return new DataTables<UserDetails>(sEcho, userDetails, userDetails.size(), total);
	}

	/* (非 Javadoc)
	 * Description:
	 * @see com.calf.cn.controller.BaseController#addAndUpdateHome(org.springframework.ui.Model, java.lang.String)
	 */
	@Override
	public String addAndUpdateHome(Model model, String id) {
		if (StringUtils.isNotBlank(id)) {
			model.addAttribute("entity", baseManager.get("UserDetails.getCustomerById", new Object[] { id }));
		}
		return "calfloan/Customer/addCustomer";
	}

	/* (非 Javadoc)
	 * Description:
	 * @see com.calf.cn.controller.BaseController#delete(java.lang.Long)
	 */
	@Override
	public int delete(Long id) {
		return 0;
	}


	/* (非 Javadoc)
	 * Description:
	 * @see com.calf.cn.controller.BaseController#delete(java.lang.String)
	 */
	@Override
	public int delete(String id) {
		List<String> list = new ArrayList<String>();
		list.add(id);
		return baseManager.batchDelete(list);
	}

	@Override
	public int saveAdd(UserDetails entity) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int saveUpdate(UserDetails entity) {
		// TODO Auto-generated method stub
		return 0;
	}

}
